iT邦幫忙

0

Day24 C程式 🗂️ main.c

c
  • 分享至 

  • xImage
  •  

🗂️ main.c

#include <stdio.h>
#include <time.h>
#include "maze_gen.h"
#include "search.h"
#include "display.h"
#include "analysis.h"

int main() {
    Maze maze;
    initMaze(&maze, 21, 21);
    generateMaze(&maze);

    clock_t start, end;
    int pathLength, expandedNodes;

    printf("=== Maze Escape AI ===\n");
    displayMaze(&maze);

    printf("\nChoose algorithm: 1.DFS  2.BFS  3.A*\n> ");
    int choice;
    scanf("%d", &choice);

    start = clock();
    if (choice == 1)
        DFS_Search(&maze, &pathLength, &expandedNodes);
    else if (choice == 2)
        BFS_Search(&maze, &pathLength, &expandedNodes);
    else
        AStar_Search(&maze, &pathLength, &expandedNodes);
    end = clock();

    double timeUsed = (double)(end - start) / CLOCKS_PER_SEC * 1000;

    printf("\n=== Search Result ===\n");
    displayMaze(&maze);
    printf("\nPath Length: %d | Expanded Nodes: %d | Time: %.2f ms\n",
           pathLength, expandedNodes, timeUsed);

    saveResult(choice, pathLength, expandedNodes, timeUsed);
    freeMaze(&maze);
    return 0;
}

圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言